import sun.reflect.generics.tree.Tree;

import javax.swing.tree.TreeNode;
import java.sql.SQLOutput;
import java.util.*;

import static jdk.nashorn.internal.objects.NativeDebug.map;

class Student {
    private String id;

    public Student() {

    }
    public Student(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                '}';
    }
}
public class Test {
    //前K个高频单词
    public List<String> topKFrequent(String[] words, int k) {
        //1、遍历数组 统计每个单词出现的频率
        Map<String, Integer> hashMap = new HashMap<>();
        for (String s : words) {
            if (hashMap.get(s) == null) {
                hashMap.put(s, 1);
            } else {
                hashMap.put(s, hashMap.get(s) + 1);
            }
        }
        //2、建立小根堆
        PriorityQueue<Map.Entry<String, Integer>> minHeap = new PriorityQueue<>(
                k, new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                if (o1.getValue().compareTo(o2.getValue()) == 0) {
                    return o2.getKey().compareTo(o1.getKey());
                }
                return o1.getValue().compareTo(o2.getValue());
            }
        }
        );
        //3、遍历hasMap  把里面的数据 放到小根堆
        for (Map.Entry<String, Integer> entry : hashMap.entrySet()) {
            if (minHeap.size() < k) {
                minHeap.offer(entry);
            } else {
                //小根堆放满了K个，下一个entry和堆顶元素比较
                Map.Entry<String, Integer> top = minHeap.peek();
                //堆顶的频率小于当前entry的频率 就出队，然后入队entry
                if (top.getValue().compareTo(entry.getValue()) < 0) {
                    minHeap.poll();
                    minHeap.add(entry);
                } else {
                    //频率相同的情况
                    if (top.getValue().compareTo(entry.getValue()) == 0) {
                        if (top.getKey().compareTo(entry.getKey()) > 0) {
                            minHeap.poll();
                            minHeap.add(entry);
                        }
                    }
                }
            }
        }
        //4、此时小根堆当中已经有了结果
        //System.out.println(minHeap);
        List<String> ret = new ArrayList<>();
        for (int i = 0; i < k; i++) {
            String key = minHeap.poll().getKey();
            ret.add(key);
        }
        Collections.reverse(ret);
        //System.out.println("ret: "+ret);
        return ret;
    }

    //旧键盘
    public static void func(String str1, String str2) {
        Set<Character> set = new HashSet<>();
        for(char ch : str2.toUpperCase().toCharArray()) {
            set.add(ch);
        }
        Set<Character> setBroken = new HashSet<>();
        for(char ch : str1.toUpperCase().toCharArray()) {
            if(!set.contains(ch) && !setBroken.contains(ch)) {
                setBroken.add(ch);
                System.out.print(ch);
            }
        }

    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str1 = in.nextLine();
            String str2 = in.nextLine();
            func(str1,str2);
        }
    }
    //宝石与石头
   public int numJewelsInStones(String jewels, String stones) {
        int count = 0;
        Set<Character> set = new HashSet<>();
        //1、遍历jewels
        for(int i = 0; i < jewels.length();i++) {
            char ch = jewels.charAt(i);
            set.add(ch);
        }
        //2、遍历stones
        for(int i = 0; i < stones.length(); i++) {
            char ch = stones.charAt(i);
            if(set.contains(ch)) {
                count++;
            }
        }
        return count;

}
    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }
        public TreeNode head = null;
        public TreeNode pre = null;
        public TreeNode Convert(TreeNode pRootOfTree) {
            if(pRootOfTree == null) {
                return null;
            }
            Convert(pRootOfTree.left);
            if(pre == null) {
                head = pRootOfTree;
                pre = pRootOfTree;
            }else {
                pre.right = pRootOfTree;
                pRootOfTree.left = pre;
                pre = pRootOfTree;
            }
            Convert(pRootOfTree.right);
            return head;

        }
    //只出现一次的数字
    public int singleNumber(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if (!set.contains(nums[i])) {
                set.add(nums[i]);
            } else {
                set.remove(nums[i]);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if (set.contains(nums[i])) {
                return nums[i];
            }
        }
        return -1;
    }
    public int singleNumber2(int[] nums) {
        Map<Integer,Integer> map = new HashMap<>();
        for(int x : nums) {
            if(map.get(x) == null) {
                map.put(x,1);
            }else {
                int val = map.get(x);
                map.put(x,val+1);
            }
        }
        for(Map.Entry<Integer,Integer> entry : map.entrySet()) {
            if(entry.getValue() == 1) {
                return entry.getKey();
            }
        }
        return -1;

    }

    public static void main(String[] args) {
        int array[] = {1,2,2,3,3,3,4,5,7,8,9};
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < array.length; i++) {
            if(map.get(array[i]) == null) {
                map.put(array[i],1);
            }else {
                int val = map.get(array[i]);
                map.put(array[i],val+1);
            }
        }
        for(Map.Entry<Integer,Integer> entry : map.entrySet()) {
            if(entry.getValue() > 1) {
                System.out.println("key: "+entry.getKey()+" val: "+entry.getValue());
            }
        }

    }
    public static void main8(String[] args) {
        int array[] = {1,2,2,3,3,3,4,5,7,8,9};
        Set<Integer> set = new HashSet<>();
        for(int x : array) {
            if(!set.contains(x)) {
                set.add(x);
            }else {
                System.out.println(x);
                return;
            }
        }
    }
    public static void main7(String[] args) {
        int array[] = {1,2,2,3,3,3,4,5,7,8,9};
        Set<Integer> set = new HashSet<>();
        for(int x : array) {
            set.add(x);
        }
        System.out.println(set);
    }
    public static void main6(String[] args) {
        Student student1 = new Student("1234");
        System.out.println(student1.hashCode());

        Student student2 = new Student("1234");
        System.out.println(student2.hashCode());
        HashBuck2<Student,String> hashBuck2 = new HashBuck2<>();
        hashBuck2.put(student1,"zhangsan");
        String val = hashBuck2.get(student2);
        System.out.println(val);
    }
    public static void main5(String[] args) {
        Student student1 = new Student("1234");
        System.out.println(student1.hashCode());

        Student student2 = new Student("1234");
        System.out.println(student2.hashCode());

    }
    public static void main4(String[] args) {
        HashBuck hashBuck = new HashBuck();
        hashBuck.put(1,11);
        hashBuck.put(2,22);
        hashBuck.put(5,55);
        hashBuck.put(8,88);
        hashBuck.put(3,33);
        hashBuck.put(4,44);
        hashBuck.put(6,66);
        hashBuck.put(7,77);

        Integer val = hashBuck.get(5);
        System.out.println(val);
    }
    public static void main3(String[] args) {
        Set<String> set = new TreeSet<>();
        // add(key): 如果key不存在，则插入，返回ture
        // 如果key存在，返回false
        boolean isIn = set.add("apple");
        set.add("orange");
        set.add("peach");
        set.add("banana");
        System.out.println(set.size());
        System.out.println(set);
        isIn = set.add("apple");
        // add(key): key如果是空，抛出空指针异常
        //s.add(null);

        // contains(key): 如果key存在，返回true，否则返回false
        System.out.println(set.contains("apple"));
        System.out.println(set.contains("watermelen"));
        // remove(key): key存在，删除成功返回true
        // key不存在，删除失败返回false
        // key为空，抛出空指针异常
        set.remove("apple");
        System.out.println(set);
        set.remove("watermelen");
        System.out.println(set);
        Iterator<String> it = set.iterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
    }
    public static void main2(String[] args) {
        Map<Student,Integer> treeMap = new TreeMap<>();
        //Key一定是可以比较的
        treeMap.put(new Student(),1);
        treeMap.put(new Student(),4);
        System.out.println(treeMap);

    }
    public static void main1(String[] args) {
        Map<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("hello",3);
        treeMap.put("abc",4);
        treeMap.put("the",8);
        System.out.println(treeMap);
        Integer val = treeMap.get("hello");
        System.out.println(val);

        Integer val2 = treeMap.getOrDefault("hello2",100);
        System.out.println(val2);

        Set<String> keySet = treeMap.keySet();
        System.out.println(keySet);

        Set<Map.Entry<String,Integer>> set = treeMap.entrySet();
        for(Map.Entry<String,Integer> entry : set) {
            System.out.println("key:"+entry.getKey()+"value:"+entry.getValue());
        }
    }
}














